package cn.firstquestion;

public class Commodity {
    private int comId;
    private String comName;
    private String merName;
    private int quantity;
    private int price;


    public Commodity(){

    }

    public Commodity(int comId, String comName, String merName, int quantity, int price) {
        this.setComId(comId);
        this.setComName(comName);
        this.setMerName(merName);
        this.setQuantity(quantity);
        this.setPrice(price);
    }

    public int getComId() {
        return comId;
    }

    public void setComId(int comId) {
        this.comId = comId;
    }

    public String getComName() {
        return comName;
    }

    public void setComName(String comName) {
        this.comName = comName;
    }

    public String getMerName() {
        return merName;
    }

    public void setMerName(String merName) {
        this.merName = merName;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        if (quantity>0){
            this.quantity = quantity;
        }else {
            System.out.println("这个商品没有存货了");
        }

    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        if (price > 0) {
            this.price = price;
        }else {
            System.out.println("抱歉这个商品价格不为负数");
        }
    }

    public void show(){
        int P=quantity*price;
        String meg=String.format("商品编号%d,商品名称%s,所属类别%s,商品数量%d,商品价格%d,商品总价%d",
                this.comId,this.comName,this.merName,this.quantity,this.price,quantity*price);
        System.out.println(meg);
    }
}
